package com.qianbao.dao.address;


import com.qianbao.domain.address.AddressEntity;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface AddressDao {


    /**
     * 查询用户的所有地址
     * @param customId 用户的唯一标识
     * @return 用户的地址列表
     */
    @Select("select * from sys_user_address where custom_id = #{customId}")
    public List<AddressEntity> findAllAddressList(String customId);


    /**
     * 根据addressid查询出具体的一条地址
     * @param addressId
     * @return
     */
    @Select("select * from sys_user_address where address_id = #{addressId}")
    public AddressEntity findAddressWithAddressId(String addressId);


    /**
     * 插入一条用户地址信息
     * @param entity 用户地址信息
     * @return 影响的行数
     */
    @Insert("insert into sys_user_address" +
            "(address_id,name,phone,province,city," +
            "area,address,is_default,custom_id) " +
            "values(#{address_id},#{name},#{phone},#{province}," +
            "#{city},#{area},#{address},#{is_default},#{custom_id})")
    public int saveAddress(AddressEntity entity);


    /**
     * 修改用户的某一条记录 地址信息
     * @param entity
     * @return
     */
    @Update("update sys_user_address set name = #{name}," +
            "phone = #{phone},province = #{province},city = #{city}," +
            "area = #{area},address = #{address},is_default = #{is_default} " +
            "where address_id = #{address_id}")
    public int updateAddress(AddressEntity entity);


    /**
     * 删除用户的某一条地址信息
     * @param addressId addressid
     */
    @Delete("delete from sys_user_address where address_id = #{addressId}")
    public int deleteUserAddress(String addressId);



}
